package com.chushouya.order.constants;


import com.general.framework.core.enums.IEnum;
import com.general.framework.core.lang.Lists;
import com.chushouya.order.dto.admin.order.OrderQuery;

import java.util.List;
import java.util.Objects;

/**
 * 业务员订单查询状态枚举
 * 0全部 1待接单 2待上门 3待发货 4未收成
 */
public enum ClerkOrderLogicStatusEnum implements IEnum<Integer> {

    all(0,  "全部",   Lists.emptyList()),
    waitConfirm(1,  "待接单", Lists.asList(OrderStatusEnum.WAIT_ACCEPT.value(), OrderStatusEnum.WAIT_CONFIRM.value(), OrderStatusEnum.CANCELLED.value())),
    waitVisit(2,  "待上门", Lists.asList(OrderStatusEnum.WAIT_VISIT.value())),
    //waitDeliver(3,  "待发货", Lists.asList(OrderStatusEnum.COMPLETE.value())),
    closed(3,  "未收成", Lists.asList(OrderStatusEnum.CLERK_CANCEL.value(), OrderStatusEnum.BACKOUT_CLOSED.value()));

    private Integer logicStatus;

    private String logicStatusName;

    private List<Integer> statusList;

    ClerkOrderLogicStatusEnum(Integer logicStatus, String logicStatusName, List<Integer> orderStatusList) {
        this.logicStatus = logicStatus;
        this.logicStatusName = logicStatusName;
        this.statusList = orderStatusList;
    }

    public static ClerkOrderLogicStatusEnum get(Integer logicStatus) {
        for (ClerkOrderLogicStatusEnum thisEnum : ClerkOrderLogicStatusEnum.values()) {
            if (Objects.equals(thisEnum.logicStatus, logicStatus)) {
                return thisEnum;
            }
        }
        return ClerkOrderLogicStatusEnum.all;
    }

    public List<Integer> statusList() {
        return statusList;
    }

    public OrderQuery buildQuery(OrderQuery query) {
        query.setOrderStatusList(this.statusList());
//        if (this.equals(ClerkOrderLogicStatusEnum.waitDeliver)) {
//            query.setLogisticsStatus(LogisticsStatusEnum.WAIT_DELIVERY.value());
//        }
        return query;
    }

    @Override
    public Integer value() {
        return logicStatus;
    }

    @Override
    public String named() {
        return logicStatusName;
    }
}
